package com.fc.mall.controller;

import com.fc.mall.base.object.Result;
import com.fc.mall.dto.CommonResult;
import com.fc.mall.model.PmsFeightTemplate;
import com.fc.mall.service.PmsFeightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Sunny on 2019/6/18.
 */
@RestController
@RequestMapping("/feight")
public class PmsFeightController {

    @Autowired
    private PmsFeightService pmsFeightService;

    @GetMapping("list")
    public CommonResult handleGetFeightList(@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                            @RequestParam(name = "pageNum") Integer pageNum)
    {
        List<PmsFeightTemplate> feightTemplates = pmsFeightService.queryList(pageSize, pageNum);
        return  new CommonResult().pageSuccess(feightTemplates);
    }

    @PostMapping("add")
    public Result handleCreateFeight(@RequestBody PmsFeightTemplate feightTemplate)
    {
        pmsFeightService.addFeightTemplate(feightTemplate);
        return Result.success();
    }

    @PutMapping("update")
    public Result handleUpdateFeight(@RequestBody PmsFeightTemplate feightTemplate)
    {
        pmsFeightService.updateFeightTemplate(feightTemplate);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result handleGetFreightTemplateById(@PathVariable Long id)
    {
        return Result.success(pmsFeightService.queryById(id));
    }

    @DeleteMapping("/{id}")
    public Result handleDelFreight(@PathVariable Long id)
    {
        pmsFeightService.delFreightTemplate(id);
        return Result.success();
    }
}
